<!DOCTYPE html>
<html>
<head></head><title></title>
		<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
	   <script src="jquery-3.3.1.min.js"></script>
	   <script src="bootstrap/js/bootstrap.js"></script>

<body>

<button type="button" class="but" onclick="languages()">解析2</button>
<button type="button" class="but" onclick="bookmark()">解析3</button>

<div id="two">结果</div>
<div id="three">结果</div>

<script>
	//var json1 = {name: 'Amit', marks: 97, distinction: true}
	/*var json1 = '[{name: "Amit", marks: 97, distinction: true}]'
	JSON.parse(json1);*/

	
	
	
	var books = {
    "Pascal" : [ 
        { "Name"  : "Pascal Made Simple", "price" : 700 },
        { "Name"  : "Guide to Pascal", "price" : 400 }
    ],                       
    "Scala"  : [
        { "Name"  : "Scala for the Impatient", "price" : 1000 }, 
        { "Name"  : "Scala in Depth", "price" : 1300 }
    ]    
  }
  
  
  

  
  
  function languages(){
  var languages = {
    "Pascal" : [ 
        { "Name"  : "Pascal Made Simple", "price" : 700 },
        { "Name"  : "Guide to Pascal", "price" : 400 }
    ],                       
    "Scala"  : [
        { "Name"  : "Scala for the Impatient", "price" : 1000 }, 
        { "Name"  : "Scala in Depth", "price" : 1300 }
    ]    
  }
  
  for(var i=0;i<languages.Pascal.length;i++){
 // document.write(languages.Pascal[i].Name+"  "+languages.Pascal[i].price);
 $("#two").append("</br>"+languages.Pascal[i].Name+" " + languages.Pascal[i].price+"</br>") 


  }
  for(var j=0;j<languages.Scala.length;j++){
   $("#two").append(languages.Scala[j].Name+"  "+languages.Scala[j].price+"</br>");
  }
  }
  
  
  
  


  
  
  /*
  var bookmark=
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Product",
    "description": "A product from Acme's catalog",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        },
        "name": {
            "description": "Name of the product",
            "type": "string"
        },
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        }
    },
    "required": ["id", "name", "price"]
}
*/
/*
for (var x in array) {
    if (typeof array[x] == 'object' && array[x] != null) {
        for (var y in array[x]) {
            alert("key = " + y + " value = " + array[x][y]);
        }
    } else {
        alert("key = " + x + " value = " + array[x]); // 非array object
    }
}
*/
  

 function bookmark(){
  var bookmark=
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Product",
    "description": "A product from Acme's catalog",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        },
        "name": {
            "description": "Name of the product",
            "type": "string"
        },
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        }
    },
    "required": ["id", "name", "price"]
}
	
          for (var x in bookmark) {
            if (typeof bookmark[x] == 'object' && bookmark[x] != null) {
		        $("#three").append(bookmark[x].id.description + " " + bookmark[x].id.type+"</br>");  
				$("#three").append(bookmark[x].name.description + " " + bookmark[x].name.type+"</br>")
				$("#three").append(bookmark[x].price.type + " " + bookmark[x].price.minimum + " " + bookmark[x].price.exclusiveMinimum + "</br>")
			 }
			  else{
			  $("#three").append("</br>"+"keys = " + x + " values = " + bookmark[x]+"</br>"); 
			
			}
			}
    
}
</script>
</body>
</html>